<?php
namespace App\Http\Controllers\CmsApi;

use Illuminate\Http\Request;
use App\Http\Model\Hint;
use App\Http\Controllers\BaseController;
use App\Lib\Response;
use App\Http\Services\MsgServices;
use App\Http\Services\RoomMsgServices;

class MsgController extends BaseController
{
    private $msg_service;
    private $roomMsg_service;
    public function __construct(){
        $this->msg_service = new MsgServices();
        $this->roomMsg_service = new RoomMsgServices();
    }

    /**
     * 全家总动员消息
     */
    public function familyCompetitionSend(Request $request){
        $roomId = $request->post('roomId');
        $type = $request->post('type');//1=用户押注 2=回合信息
        $data = $request->post('data');
        $data = json_decode($data, true);
        if(empty($roomId) || empty($type) || empty($data)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        //用户押注
        if($type == 1) {
            $this->roomMsg_service->fcSendStack($roomId, $data);
        }
        //回合信息
        if($type == 2) {
            $this->roomMsg_service->fcSendRound($roomId, $data);
        }
        
        Response::returnResult(Hint::SUCCESS);
    }

    /**
     * 西天取经消息
     */
    public function xtqjSend(Request $request){
        $roomId = $request->post('roomId');
        $type = $request->post('type');//1=悬赏开始 2=公告 3=悬赏差的次数
        $data = $request->post('data');
        $data = json_decode($data, true);
        if(empty($roomId) || empty($type) || empty($data)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        //悬赏开始
        if($type == 1) {
            $this->roomMsg_service->xtqjSendOffer($roomId, $data);
        }
        //公告
        if($type == 2) {
            $this->roomMsg_service->xtqjSendNotice($roomId, $data);
        }
        //悬赏差的次数
        if($type == 3) {
            $this->roomMsg_service->xtqjSendOfferNeedNum($roomId, $data);
        }
        //悬赏开启关闭
        if($type == 4) {
            $this->roomMsg_service->xtqjSendOfferStatus($roomId, $data);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    /**
     * 荒漠捕牛消息
     */
    public function lassoCattleSend(Request $request){
        $roomId = $request->post('roomId');
        $type = $request->post('type');//1=用户押注 2=回合信息
        $data = $request->post('data');
        $data = json_decode($data, true);
        if(empty($roomId) || empty($type) || empty($data)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        //用户押注
        if($type == 1) {
            $this->roomMsg_service->lcSendStack($roomId, $data);
        }
        //回合信息
        if($type == 2) {
            $this->roomMsg_service->lcSendRound($roomId, $data);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    /**
     * 开运装备星消息
     */
    public function equipDrawSend(Request $request){
        $roomId = $request->post('roomId');
        $data = $request->post('data');
        $data = json_decode($data, true);
        if(empty($roomId) || empty($data)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $this->roomMsg_service->equipDrawSendNotice($roomId, $data);

        Response::returnResult(Hint::SUCCESS);
    }

    /**
     * 双旦节2023留言板通知
     */
    public function sdj2023LybMsg(Request $request){
        $fromUserId = $request->input('fromUserId');
        $toUserId = $request->input('toUserId');
        $msg = $request->input('msg');
        $createTime = $request->input('createTime');
        $endTime = $request->input('endTime');
        $jumpUrl = $request->input('jumpUrl');
        if(empty($fromUserId) || empty($toUserId) || empty($msg)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $this->msg_service->lybMsg($fromUserId, $toUserId, $msg, $createTime, $endTime, $jumpUrl);

        Response::returnResult(Hint::SUCCESS);
    }

    /**
     * 三国群英消息
     */
    public function grasslandSheepSend(Request $request){
        $roomId = $request->post('roomId');
        $type = $request->post('type');//1=用户押注 2=回合信息
        $data = $request->post('data');
        $data = json_decode($data, true);
        if(empty($roomId) || empty($type) || empty($data)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        //用户押注
        if($type == 1) {
            $this->roomMsg_service->glSendStack($roomId, $data);
        }
        //回合信息
        if($type == 2) {
            $this->roomMsg_service->glSendRound($roomId, $data);
        }

        Response::returnResult(Hint::SUCCESS);
    }

}
